<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020-06-02
 * Time: 14:04
 */
namespace app\index\controller;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class Redislist extends Command{
    protected function configure()
    {
        $this->setName('redis')->setDescription('Here is the remark ');
    }

    protected function execute(Input $input, Output $output)
    {


        $redis = new \Redis();

        $redis->pconnect('127.0.0.1', 6379);//serverip port
        $redis->select(1);


        $i = 0;
       while(true){
            $i++;
            $values = $redis->lPop('form_data');
            if ($values){
                    list($vid,$uid)=explode('||',$values);
//                    $dtdata=$redis->get('dt_'.$vid.'_'.$uid);
//                    if (!$dtdata)continue;
//                    //终止本次循环 if (!$dtdata)continue;
//                    $dtdata = json_decode($dtdata,1);
//
//                    $dtdatas=array();
//                    foreach ($dtdata as $v){
//                        $dtdatas[]= array(
//                            'openid'=>$uid,
//                            'subject_id'=>$v['sid'],
//                            'name'=>$v['ans'],
//                            'answer'=>'',
//                            'status'=>$v['status'],
//                            'createtime'=>time(),
//                            'volume_id'=>$vid
//                        );
//
//
//                    }
//
//                    Db::name('ques_log')->insertAll($dtdatas);
//                    $dtdatas=null;

                    $formData=$redis->get('form_'.$vid.'_'.$uid);

                    if (!$formData)continue;
                    $formData = json_decode($formData,1);


                    $formData['createtime']=time();
                    if (!$formData['tableName'])continue;
                    $tableName=$formData['tableName'];
                    unset($formData['tableName']);
                    $fid = Db::name($tableName)->insert($formData,0,1);
                    $Round = new \app\admin\model\activtyc\Round;
                    $post = [
                        'id'=>$redis->get('nums'),
                        'name'=>$formData['name'],
                        'phone'=>$formData['phone'],
                        'parent_name'=>$formData['parent_name'],
                        // 'type'=>$info['type'],
                        'volumename'=>TableField('Volume','name',$formData['volume_id']),
                        'schoolname'=>TableField('School_B','name',$formData['school_id']),
                        'classname'=>$formData['classname'],
                        'moban'=>$vid==34 ? 'xiaoxue' : 'round'
                    ];
//                    $diqu = $Round->getProvinceOrderList();
//                    $shen_text = isset($diqu[$formData['shen']]) ? $diqu[$formData['shen']] : '';
//                    $shi_text = isset($diqu[$formData['shi']]) ? $diqu[$formData['shi']] : '';
//                    $xian_text = isset($diqu[$formData['xian']]) ? $diqu[$formData['xian']] : '';
//                    $post = [
//                        'id'=>$redis->get('nums'),
//                        'name'=>$formData['name'],
//                        'phone'=>$formData['phone'],
//                        'parent_name'=>$formData['parent_name'],
//                        'address'=>$shen_text.$shi_text.$xian_text,
//                        'text'=>$formData['address'],
//                        // 'type'=>$info['type'],
//                        'volumename'=>TableField('Volume','name',$formData['volume_id']),
//                        'schoolname'=>TableField('School_B','name',$formData['school_id']),
//                        'classname'=>$formData['classname'],
//                        'moban'=>$vid==34 ? 'xiaoxue' : 'round'
//                    ];
                    $redis->incr('nums');
                    $response = \fast\Http::post('http://oa.fc62.com/index/Assistant/chant',$post);
                    unset($vid,$uid,$dtdata,$formData,$fid,$diqu,$shen_text,$shi_text,$xian_text,$post,$Round);



                    echo 'success'.PHP_EOL;
            }
            if($i > 20000)$i=0;

            if($i%30==0){
                $output->writeln($i.PHP_EOL);
                $values=null;
                usleep(300000);
            }


        }

    }
}
